#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
ll a[10010];

int main()
{
    IOS;
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }    
    do{
        if(m==0){
            cout<<a[0];
            for(ll i=1;i<n;i++){
                cout<<" "<<a[i];
            }
            cout<<endl;
            break;
        }
        m--;
    }while(next_permutation(a,a+n));

    getchar();
    getchar();
    return 0;
}
